<?php
require 'Admin/Model/Model.php';
	class CommentsModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getCommentsList(){
			$sql = "select * from comments";
		    $data = $this->conn->query($sql);
			return $data;
		}
		
	


             function addComments($data){
			//var_dump($data);
			  $Comments = array(
					//'cid' => trim($data['cid']),
					'uid' => $data['uid'], 					 
					'nid'=> $data['nid'],
					'comment' => $data['comment']
								
				
			  	);
			  $keys = implode(',',array_keys($Comments));
			  $values = implode("','", array_values($Comments));
			  $sql="insert into comments ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
			 
				$result = $this->conn->query($sql);
					return $result;
			  
		}
			function getCommentsByID($id){
			$sql = "select * from comments where nid=".$id;
		    $result = $this->conn->query($sql);
	      	return $result;
		}


		function updateComments($data){
			//var_dump($data);
			$Comments = array(
					//'cid' => trim($data['cid']),  
					'comment' => trim($data['comment'])
				

			  	);
			
			 $sets = '';
			  foreach ($Comments as $key=>$val){
			        $sets.=$key."='".$val."',";
			  }
			    $sets=rtrim($sets,','); //去掉SQL里的最后一个逗号
			   
			    $sql="UPDATE comments SET {$sets} where cid=".$data['id'];
			  //执行SQL语句
				$result = $this->conn->query($sql);
				//var_dump($result);
					return $result;
			  
		}

		function delComments($id){
			$sql1 = "select * from comments where cid=".$id;
			$data1 = $this->conn->query($sql1);		
			$sql = "delete from comments where cid=".$id;
			
			$result = $this->conn->query($sql);
			return $result;
		}
		function Search($data){

			$sql="select * from comments where commentsname like '%".$data."%'";
			//echo $sql;
			$result = $this->conn->query($sql);
			return $result;
		}
	}
?>